package health.lm.com.component_base.popup.model;

import org.json.JSONObject;

import health.lm.com.component_base.popup.share.SharePopBean;
import health.lm.com.component_base.popup.share.ShareTextBean;
import health.lm.com.component_base.popup.sign.SignPopResultBean;
import health.lm.com.component_base.popup.upgrade.ThinkTankLevelUpEntity;
import health.lm.com.component_base.popup.uplevel.UpLevelBean;
import health.lm.com.data.App;
import health.lm.com.data.HttpCST;
import health.lm.com.network.EasyHttp;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.network.utils.MyApi;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;


/**
 * Introduce:
 * <p>
 * Create By JueShou -- 2019-07-25 10:32
 * Project: ujiankang
 */
public class PopupModel {
    private static PopupModel sPopupModel;

    private PopupModel() {
    }

    public static PopupModel getInstance() {
        //String token = "TtYHQrNfLMMBDaKunkFzbhbrmeU5Hy/2teu+//QNQ89Ocez4qKwTmtWwAZyNdxduwB5bCM00wBpiB9mU81sdlrxx3al5Fg0ItC4xy9AK53p4XFYSzeXFgfsAhhgyLyww";
        //App.model.setAccess_token(token);
        if (null == sPopupModel) sPopupModel = new PopupModel();
        return sPopupModel;
    }

    /**
     * 会员等级提升
     *
     * @param pCallBack pCallBack
     */
    public void PopUpLevel(SimpleCallBack<UpLevelBean> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1027, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 获取会员签到信息
     *
     * @param pCallBack pCallBack
     */
    public void getSignInfo(SimpleCallBack<SignPopResultBean> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1025, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 会员签到提交
     *
     * @param pCallBack pCallBack
     */
    public void getSigned(SimpleCallBack<SignPopResultBean> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1026, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 荣誉等级提升进度
     *
     * @param pCallBack pCallBack
     */
    public void levelUp(SimpleCallBack<ThinkTankLevelUpEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_WISDOM, HttpCST.INTFC_1002, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }


    /**
     * 商品分享
     *
     * @param id        商品ID
     * @param pCallBack observer
     */
    public void shareProduct(String id, SimpleCallBack<SharePopBean> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            jsonObject.put(HttpCST._id, id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_NEWS, HttpCST.INTFC_1008, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }


    /**
     * 分享图片
     *
     * @param id       资讯列表
     * @param pCallBack pCallBack
     */
    public void shareImg(String id, SimpleCallBack<SharePopBean> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            jsonObject.put(HttpCST._id, id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_NEWS, HttpCST.INTFC_1006, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    public void NewsShareResult(String id, SimpleCallBack<UpLevelBean> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            jsonObject.put(HttpCST._id, id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_NEWS, HttpCST.INTFC_1007, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 文字分享 资讯分享链接
     */
    public void textShare(String type ,String id,SimpleCallBack<ShareTextBean> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.model.getAccess_token());
            jsonObject.put(HttpCST.TYPE, type);
            jsonObject.put(HttpCST._id, id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_NEWS, HttpCST.INTFC_1012, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }
}
